package com.cy.controller;


import com.cy.pojo.Admi;
import com.cy.pojo.GoodsSingle;
import com.cy.pojo.PageBean;
import com.cy.pojo.Show;
import com.cy.service.Showservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;

@RestController//定义bean
public class ShowController {

    @Autowired
    private Showservice sser;

    @RequestMapping("/selectShowCar")
    public ArrayList selectShowCar(HttpSession session){
        String id =session.getId();
        ArrayList <GoodsSingle>attribute = (ArrayList) session.getAttribute(id + "shopCar");
        for (GoodsSingle single : attribute) {
            System.out.println(single.toString());
        }
        return attribute;
    }


    @RequestMapping("/selectShowPage")
    public PageBean<Show> selectShowPage(String currentPage, String pageSize) {
        int _currentPage = Integer.parseInt(currentPage);
        int _pageSize = Integer.parseInt(pageSize);
        PageBean<Show> showPageBean = sser.selectShowPage(_currentPage, _pageSize);
        return showPageBean;
    }

    @RequestMapping("/selectShowNames")
    public PageBean<Show> selectShowNames(String names, String currentPage, String pageSize) {
        //接受参数
        if (names == "") {
            return this.selectShowPage(currentPage, pageSize);
        }else {
            return sser.selectShowNames(names);
        }
    }

    @RequestMapping("/selectShowType")

    public PageBean<Show> selectShowType(String type, String currentPage, String pageSize) {
        //接受参数
        if (type.equals("全部")) {
            return this.selectShowPage(currentPage, pageSize);
        }else{
            //调用方法
            return sser.selectShowType(type);
        }
    }

    @RequestMapping("/selectShowAll")

    public ArrayList<Show> selectShowAll(){
        return sser.selectShowAll();
    }

    @RequestMapping("/selectZhuce")

    public ArrayList<Admi> selectZhuce(){
        return sser.selectZhuce();
    }

    @RequestMapping("/deleteShowNames")
    @ResponseBody
    public void deleteShowNames(String names, String sellers){
        sser.deleteShowNames(names,sellers);
    }


    @RequestMapping("/agreeApply")
    public void agreeApply(String name, String password){
        sser.insertxingxi(name,password);
        sser.deleteZhuce(name,password);
    }

    @RequestMapping("/deleteZhuce")
    public void deleteZhuce(String name, String password){
        sser.deleteZhuce(name,password);
    }

    @RequestMapping("/selectSellerNames")

    public ArrayList<Show> selectSellerNames(String seller){
        return sser.selectSellerNames(seller);
    }

    @RequestMapping(value = "/insertShow" ,method = RequestMethod.POST)
    public void  insertShow(@RequestParam("names") String names, @RequestParam("numbers")int numbers, @RequestParam("prices")int prices, @RequestParam("type")String type, HttpSession session){
        /*String seller=(String) session.getAttribute("user");*/
        String seller="唐庆";
        sser.insertshow(names,prices,seller,numbers,type);
    }




}
